package com.lpw.dbvideo.user.dao;

import com.lpw.dbvideo.user.domain.User;
import com.lpw.dbvideo.user.provider.UserProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * user数据访问层
 */
public interface UserMapper {

    /**
     * 新增user对象
     * @param user 新增的user对象
     * @return
     */
    @InsertProvider(type = UserProvider.class,method = "insertUser")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id") // 拿到新增后生成的id
    int save(User user);
    /**
     * 根据id查询用户
     * @param id 用户id
     * @return
     */
    @Select("select * from user where id = #{Id}")
    User findById(@Param(value = "Id") int id);

    /**
     * 根据openid查询用户
     * @param openId 查询条件 openid
     * @return
     */
    @Select("select * from user where openid = #{openId}")
    User findByOpenId(@Param(value = "openId") String openId);

    /**
     * 查询所有用户
     * @return
     */
    @Select("select * from user")
    List<User> findAll();

    /**
     * 根据id更新用户
     * @param user 需要更新的用户信息
     */
    @UpdateProvider(type = UserProvider.class,method = "updateUser")
    int update(User user);

    /**
     * 根据id删除用户
     * @param id 需要删除的用户id
     */
    @Delete("delete from user where id =#{id}")
    void delete(int id);
}